﻿<?php
include_once('common/header.php');	
if($AppUI->id <= 0) {
	$this->_redirect(HOST_VFRIEND);
}
$oFile	= $_FILES['pavatar'];
if(isset($oFile) && $oFile) {
	$arrImg = Globals::uploadAvatar($oFile);
	if($arrImg['error'] == 0) {		
		$objPhoto 	= new Photo();
		$objPhoto->unlinkImg($AppUI->id, $AppUI->imageid);
		$arrResult	= $objPhoto->add($AppUI->id, $arrImg['path']);
		$intImageId	= isset($arrResult['imageid']) ? $arrResult['imageid'] : 0;
		$isUpdate	= isset($arrResult['is_update']) ? $arrResult['is_update'] : 0;		
		if($intImageId > 0) {
			$AppUI->image_path					= $arrImg['path'];
			$_SESSION['Zend_Auth']['storage'] 	= $AppUI;
		}		
		Vfriend_Function::setMsg($arrMessage[1]);
		Vfriend_Function::redirect(LINK_ACCOUNT_INDEX);
	}
	else {
		Vfriend_Function::setError($arrImg['error']);	
		Vfriend_Function::redirect(LINK_ACCOUNT_INDEX);
	}
} 
Vfriend_Function::redirect(LINK_ACCOUNT_INDEX);
exit();
?>